﻿using System;
using System.Collections.Generic;
using System.Text;
using DecodeInterface;
using System.Drawing;
using System.Windows.Forms;

namespace DecodeLibrary
{
    public class DecodeYV12ToGrey : DecodeIntPtr
    {
        protected override unsafe object[] OnDecode(byte* pIn, byte* pOut, Size sizeIn, Size sizeOut, params object[] state)
        {
            byte* yData = pIn;
            int W = sizeOut.Width, H = sizeOut.Height;
            long size = W * H;
            int indexY = 0;

            byte* pOutGrey = pOut;

            for (int h = 0; h < H; h++)
            {
                for (int w = 0; w < W; w++)
                {
                    indexY = h * W + w;

                    pOutGrey[indexY * 3] =
                        pOutGrey[indexY * 3 + 1] =
                        pOutGrey[indexY * 3 + 2] =
                        yData[indexY];
                }
            }

            return null;
        }
    }
}
